﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace syc.Jidong
{
    public partial class 设备内部转移 : System.Web.UI.Page
    {
        private void ShowMessage(string msg)
        {
            this.Panel_Msg.Visible = true;
            this.Message.Text = "·" + msg;
        }
        protected void Page_Load(object sender, EventArgs e)
        {

            int id = 0;
            this.Message.Text = "·准备就绪";
            if (!this.IsPostBack)
            {
                this.Date3.Text = DateTime.Today.ToLongDateString();
                if (Request.QueryString["ID"] != null)
                {
                    int.TryParse(Request.QueryString["ID"], out id);
                }
                if (id > 0)
                {
                    this.BillID.Text = id.ToString();
                    this.SqlDataSource1.SelectParameters["ID"].DefaultValue = id.ToString();
                    this.SqlDataSource1.Select(DataSourceSelectArguments.Empty);
                }
            }

        }

        protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
        {
            if (e.Command.Parameters[1].Value == DBNull.Value)
            {
                return;
            }
            this.BianHao0.Text = (string)e.Command.Parameters[1].Value;
            this.MingCheng.Text = (string)e.Command.Parameters[2].Value;
            this.XingHao.Text = (string)e.Command.Parameters[3].Value;

            this.YuanZhi.Text = ((decimal)e.Command.Parameters[4].Value).ToString("0.00");

            if (e.Command.Parameters[5].Value != DBNull.Value)
            {
                this.Date1.Text = ((DateTime)e.Command.Parameters[5].Value).ToLongDateString();
            }

            this.NianXian.Text = ((short)e.Command.Parameters[6].Value).ToString();
            this.ChuChangBH.Text = (string)e.Command.Parameters[7].Value;

            if (e.Command.Parameters[8].Value != DBNull.Value)
            {
                //this.Date2.Text = ((DateTime)e.Command.Parameters[8].Value).ToLongDateString();
                this.Date2.Text = (string)e.Command.Parameters[8].Value;
            }
            this.DiDian0.Text = (string)e.Command.Parameters[9].Value;

        }

        protected void Button_Save_Click(object sender, EventArgs e)
        {
            if (this.BianHao.Text.Length != 18)
            {
                this.ShowMessage("新编号录入有误");
                return;
            }
            char[] cc = this.BianHao.Text.ToCharArray();
            for (int i = 0; i < cc.Length; i++)
            {
                if (cc[i] > '9' || cc[i] < '0')
                {
                    this.ShowMessage("编号只能录入数字");
                    return;
                }
            }
            DateTime d;
            if (!DateTime.TryParse(this.Date3.Text, out d))
            {
                this.ShowMessage("转移日期录入有误");
                return;
            }
            this.SqlDataSource1.UpdateParameters["ID"].DefaultValue = this.BillID.Text;
            this.SqlDataSource1.UpdateParameters["编码"].DefaultValue = this.BianHao0.Text;
            this.SqlDataSource1.UpdateParameters["新编码"].DefaultValue = this.BianHao.Text;
            this.SqlDataSource1.UpdateParameters["安装地点"].DefaultValue = this.DiDian0.Text;
            this.SqlDataSource1.UpdateParameters["新地点"].DefaultValue = this.DiDian.Text;
            this.SqlDataSource1.UpdateParameters["单据号"].DefaultValue = this.ZiHao.Text;
            this.SqlDataSource1.UpdateParameters["日期"].DefaultValue = d.ToShortDateString();
            this.SqlDataSource1.UpdateParameters["备注"].DefaultValue = this.BeiZhu.Text;
            if (this.SqlDataSource1.Update() > 0)
            {
                this.ShowMessage("转移成功");
                this.Button_Save.Visible = false;
            }
        }
    }
}
